using System;
using System.Timers;

namespace RxjhServer
{
    public class 追加状态类 : IDisposable
    {
        public System.Timers.Timer npcyd;

        public DateTime time;

        public Players Play;

        private int _FLD_PID;

        private int _FLD_RESIDE1;

        private int _FLD_总时间;

        public int FLD_PID
        {
            get
            {
                return _FLD_PID;
            }
            set
            {
                _FLD_PID = value;
            }
        }

        public int FLD_RESIDE1
        {
            get
            {
                return _FLD_RESIDE1;
            }
            set
            {
                _FLD_RESIDE1 = value;
            }
        }

        public int FLD_总时间
        {
            get
            {
                return _FLD_总时间;
            }
            set
            {
                _FLD_总时间 = value;
            }
        }

        public int FLD_sj
        {
            get
            {
                return getsj();
            }
        }

        public void Dispose()
        {
            if (World.jlMsg == 1)
            {
                Form1.WriteLine(0, "追加状态类-Dispose");
            }
            if (npcyd != null)
            {
                npcyd.Enabled = false;
                npcyd.Close();
                npcyd.Dispose();
                npcyd = null;
            }
            Play = null;
        }

        ~追加状态类()
        {
            if (npcyd != null)
            {
                npcyd.Enabled = false;
                npcyd.Close();
                npcyd.Dispose();
                npcyd = null;
            }
        }

        public 追加状态类(Players Play_, int 时间, int 物品ID, int FLD_RESIDE1)
        {
            FLD_PID = 物品ID;
            this.FLD_RESIDE1 = FLD_RESIDE1;
            time = DateTime.Now;
            time = time.AddMilliseconds(时间);
            FLD_总时间 = 时间 - 20000;
            Play = Play_;
            npcyd = new System.Timers.Timer(时间);
            npcyd.Elapsed += 时间结束事件2;
            npcyd.Enabled = true;
            npcyd.AutoReset = false;
        }

        public void 时间结束事件2(object source, ElapsedEventArgs e)
        {
            if (World.jlMsg == 1)
            {
                Form1.WriteLine(0, "追加状态类-时间结束事件2");
            }
            时间结束事件();
        }

        public void 时间结束事件()
        {
            if (World.jlMsg == 1)
            {
                Form1.WriteLine(0, "追加状态类-时间结束事件()");
            }
            try
            {
                if (npcyd != null)
                {
                    npcyd.Enabled = false;
                    npcyd.Close();
                    npcyd.Dispose();
                    npcyd = null;
                }
                bool flag = false;
                if (Play != null)
                {
                    using (new Lock(Play.追加状态列表, "追加状态列表"))
                    {
                        if (Play.追加状态列表.ContainsKey(FLD_PID))
                        {
                            switch (FLD_PID)
                            {
                                case 900000467:
                                    Play.FLD_人物_追加_攻击 -= 10;
                                    Play.FLD_人物_追加_防御 -= 10;
                                    Play.人物追加最大_HP -= 250;
                                    Play.人物追加最大_MP -= 150;
                                    Play.更新武功和状态();
                                    Play.更新HP_MP_SP();
                                    break;
                                case 1000000123:
                                    Play.人物追加最大_HP -= 300;
                                    if (Play.人物_HP > Play.人物最大_HP)
                                    {
                                        Play.人物_HP = Play.人物最大_HP;
                                    }
                                    Play.更新HP_MP_SP();
                                    break;
                                case 1000000124:
                                    Play.FLD_人物_追加_攻击 -= 20;
                                    Play.更新武功和状态();
                                    break;
                                case 1000000125:
                                    Play.FLD_人物_追加_防御 -= 20;
                                    Play.更新武功和状态();
                                    break;
                                case 1000000126:
                                    Play.人物追加最大_HP -= 200;
                                    if (Play.人物_HP > Play.人物最大_HP)
                                    {
                                        Play.人物_HP = Play.人物最大_HP;
                                    }
                                    Play.更新HP_MP_SP();
                                    break;
                                case 1007000005:
                                    Play.人物追加最大_HP -= 300;
                                    if (Play.人物_HP > Play.人物最大_HP)
                                    {
                                        Play.人物_HP = Play.人物最大_HP;
                                    }
                                    Play.更新HP_MP_SP();
                                    break;
                                case 1007000006:
                                    Play.人物追加最大_HP -= 500;
                                    if (Play.人物_HP > Play.人物最大_HP)
                                    {
                                        Play.人物_HP = Play.人物最大_HP;
                                    }
                                    Play.更新HP_MP_SP();
                                    break;
                                case 1007000007:
                                    Play.人物追加最大_HP -= 700;
                                    if (Play.人物_HP > Play.人物最大_HP)
                                    {
                                        Play.人物_HP = Play.人物最大_HP;
                                    }
                                    Play.更新HP_MP_SP();
                                    break;
                                case 501301:
                                    Play.dllFLD_追加百分比_攻击(Play.太极五形状态增加);
                                    Play.更新武功和状态();
                                    break;
                                case 501302:
                                    Play.dllFLD_追加百分比_防御(Play.太极八卦状态增加);
                                    Play.更新武功和状态();
                                    break;
                                case 501303:
                                    Play.dllFLD_追加百分比_防御(Play.太极罡气状态增加);
                                    Play.更新武功和状态();
                                    break;
                                case 501401:
                                    Play.FLD_追加百分比_命中 -= Play.强筋护体状态增加;
                                    Play.更新武功和状态();
                                    break;
                                case 501402:
                                    Play.FLD_追加百分比_回避 -= Play.身轻如燕状态增加;
                                    Play.更新武功和状态();
                                    break;
                                case 501403:
                                    Play.FLD_追加百分比_HP上限 -= Play.九转回心状态增加;
                                    if (Play.人物_HP > Play.人物最大_HP)
                                    {
                                        Play.人物_HP = Play.人物最大_HP;
                                    }
                                    Play.更新HP_MP_SP();
                                    break;
                                case 501603:
                                    Play.FLD_追加百分比_回避 -= 0.1;
                                    Play.更新武功和状态();
                                    break;
                                case 401202:
                                    Play.FLD_人物_追加_命中 -= 40;
                                    Play.FLD_人物_追加_回避 += 20;
                                    Play.更新武功和状态();
                                    break;
                                case 401203:
                                    Play.FLD_人物_追加_命中 += 20;
                                    Play.FLD_人物_追加_回避 -= 40;
                                    Play.更新武功和状态();
                                    break;
                                case 9000120:
                                case 9009150:
                                    Play.FLD_人物_追加_经验百分比 -= 0.2;
                                    if (Play.FLD_人物_追加_经验百分比 < 0.0)
                                    {
                                        Play.FLD_人物_追加_经验百分比 = 0.0;
                                    }
                                    break;
                                case 401301:
                                    Play.FLD_人物_武功攻击力增加百分比 -= 0.1;
                                    Play.更新武功和状态();
                                    break;
                                case 401302:
                                    Play.FLD_人物_武功防御力增加百分比 -= 0.1;
                                    Play.更新武功和状态();
                                    break;
                                case 601101:
                                    Play.行走状态(BitConverter.GetBytes(FLD_PID), 1);
                                    Play.行走状态id = 1;
                                    Play.重新计算当前坐标(1);
                                    break;
                                case 601102:
                                    Play.行走状态(BitConverter.GetBytes(FLD_PID), 1);
                                    Play.行走状态id = 1;
                                    Play.重新计算当前坐标(1);
                                    break;
                                case 601103:
                                    Play.行走状态(BitConverter.GetBytes(FLD_PID), 1);
                                    Play.行走状态id = 1;
                                    break;
                                case 700201:
                                    Play.状态效果人物灵兽(BitConverter.GetBytes(FLD_PID), 0, 300000);
                                    Play.人物灵兽.FLD_回避 -= 50;
                                    Play.人物灵兽.FLD_命中 -= 50;
                                    Play.更新灵兽武功和状态();
                                    break;
                                case 700202:
                                    Play.状态效果人物灵兽(BitConverter.GetBytes(FLD_PID), 0, 300000);
                                    Play.人物灵兽.FLD_攻击 -= 50;
                                    Play.更新灵兽武功和状态();
                                    break;
                                case 700203:
                                    Play.状态效果人物灵兽(BitConverter.GetBytes(FLD_PID), 0, 300000);
                                    Play.人物灵兽.FLD_防御 -= 50;
                                    Play.更新灵兽武功和状态();
                                    break;
                                case 700301:
                                    Play.状态效果人物灵兽(BitConverter.GetBytes(FLD_PID), 0, 300000);
                                    Play.人物灵兽.FLD_MP_MAX -= 200;
                                    Play.人物灵兽.FLD_HP_MAX -= 200;
                                    Play.更新灵兽武功和状态();
                                    Play.更新灵兽HP_MP_SP();
                                    break;
                                case 700302:
                                    Play.状态效果人物灵兽(BitConverter.GetBytes(FLD_PID), 0, 300000);
                                    Play.人物灵兽.FLD_武功攻击 -= 50;
                                    Play.更新灵兽武功和状态();
                                    break;
                                case 700303:
                                    Play.状态效果人物灵兽(BitConverter.GetBytes(FLD_PID), 0, 300000);
                                    Play.人物灵兽.FLD_武功防御 -= 50;
                                    Play.更新灵兽武功和状态();
                                    break;
                                case 700401:
                                    Play.宠物行走状态id = 1;
                                    Play.行走状态人物灵兽(BitConverter.GetBytes(FLD_PID), 1);
                                    Play.状态效果人物灵兽(BitConverter.GetBytes(FLD_PID), 0, 300000);
                                    break;
                                case 700402:
                                    Play.宠物行走状态id = 1;
                                    Play.行走状态人物灵兽(BitConverter.GetBytes(FLD_PID), 1);
                                    Play.状态效果人物灵兽(BitConverter.GetBytes(FLD_PID), 0, 300000);
                                    break;
                                case 700403:
                                    Play.宠物行走状态id = 1;
                                    Play.行走状态人物灵兽(BitConverter.GetBytes(FLD_PID), 1);
                                    Play.状态效果人物灵兽(BitConverter.GetBytes(FLD_PID), 0, 300000);
                                    break;
                                case 700014:
                                    Play.dllFLD_追加百分比_攻击(Play.怒气效果状态增加);
                                    Play.dllFLD_追加百分比_防御(Play.怒气效果状态增加);
                                    flag = true;
                                    Play.更新武功和状态();
                                    break;
                                case 9000121:
                                case 9000122:
                                case 9001207:
                                case 9009076:
                                    Play.FLD_人物_追加_经验百分比 -= 0.2;
                                    break;
                                case 1008000016:
                                    Play.dllFLD_追加百分比_攻击(0.1);
                                    break;
                                case 1008000017:
                                    Play.dllFLD_追加百分比_防御(0.1);
                                    break;
                                case 1008000018:
                                    Play.dllFLD_装备_追加_武器_强化(2);
                                    Play.计算人物装备数据();
                                    Play.更新武功和状态();
                                    break;
                                case 1008000019:
                                    Play.dllFLD_装备_追加_防具_强化(1);
                                    Play.计算人物装备数据();
                                    Play.更新武功和状态();
                                    break;
                                case 201201:
                                    Play.dllFLD_追加百分比_攻击(0.02);
                                    Play.更新武功和状态();
                                    break;
                                case 301201:
                                    Play.dllFLD_追加百分比_攻击(0.01);
                                    Play.FLD_追加百分比_HP上限 -= 0.05;
                                    if (Play.人物_HP > Play.人物最大_HP)
                                    {
                                        Play.人物_HP = Play.人物最大_HP;
                                    }
                                    Play.更新武功和状态();
                                    break;
                                case 401401:
                                    Play.FLD_追加百分比_命中 -= 0.04;
                                    Play.FLD_追加百分比_HP上限 -= 0.02;
                                    if (Play.人物_HP > Play.人物最大_HP)
                                    {
                                        Play.人物_HP = Play.人物最大_HP;
                                    }
                                    Play.更新武功和状态();
                                    break;
                                case 1008000165:
                                    Play.人物追加最大_HP -= 700;
                                    if (Play.人物_HP > Play.人物最大_HP)
                                    {
                                        Play.人物_HP = Play.人物最大_HP;
                                    }
                                    Play.dllFLD_追加百分比_攻击(0.1);
                                    Play.dllFLD_追加百分比_防御(0.1);
                                    Play.FLD_人物_武功攻击力增加百分比 -= 0.05;
                                    Play.FLD_人物_武功防御力增加百分比 -= 0.1;
                                    Play.更新武功和状态();
                                    Play.更新HP_MP_SP();
                                    break;
                                case 1008000156:
                                    Play.人物追加最大_HP -= 300;
                                    if (Play.人物_HP > Play.人物最大_HP)
                                    {
                                        Play.更新HP_MP_SP();
                                    }
                                    flag = true;
                                    break;
                                case 1008000187:
                                    Play.人物追加最大_HP -= 300;
                                    if (Play.人物_HP > Play.人物最大_HP)
                                    {
                                        Play.人物_HP = Play.人物最大_HP;
                                    }
                                    Play.FLD_人物_追加_气功--;
                                    Play.更新武功和状态();
                                    Play.更新HP_MP_SP();
                                    flag = true;
                                    break;
                                case 1008000183:
                                    Play.人物追加最大_HP -= 300;
                                    if (Play.人物_HP > Play.人物最大_HP)
                                    {
                                        Play.人物_HP = Play.人物最大_HP;
                                    }
                                    Play.dllFLD_追加百分比_防御(0.05);
                                    Play.更新武功和状态();
                                    Play.更新HP_MP_SP();
                                    flag = true;
                                    break;
                                case 1008000095:
                                    Play.FLD_人物_追加_经验百分比 -= 0.2;
                                    if (Play.FLD_人物_追加_经验百分比 < 0.0)
                                    {
                                        Play.FLD_人物_追加_经验百分比 = 0.0;
                                    }
                                    break;
                                case 1008000096:
                                    Play.FLD_人物_追加_经验百分比 -= 0.3;
                                    if (Play.FLD_人物_追加_经验百分比 < 0.0)
                                    {
                                        Play.FLD_人物_追加_经验百分比 = 0.0;
                                    }
                                    break;
                                case 1008000097:
                                    Play.FLD_人物_追加_经验百分比 -= 0.4;
                                    if (Play.FLD_人物_追加_经验百分比 < 0.0)
                                    {
                                        Play.FLD_人物_追加_经验百分比 = 0.0;
                                    }
                                    break;
                                case 1008000185:
                                    Play.人物追加最大_HP -= 700;
                                    if (Play.人物_HP > Play.人物最大_HP)
                                    {
                                        Play.人物_HP = Play.人物最大_HP;
                                    }
                                    Play.FLD_人物_追加_经验百分比 -= 0.4;
                                    if (Play.FLD_人物_追加_经验百分比 < 0.0)
                                    {
                                        Play.FLD_人物_追加_经验百分比 = 0.0;
                                    }
                                    Play.dllFLD_追加百分比_防御(0.1);
                                    Play.dllFLD_装备_追加_防具_强化(1);
                                    Play.dllFLD_装备_追加_武器_强化(2);
                                    Play.计算人物装备数据();
                                    Play.更新武功和状态();
                                    Play.更新HP_MP_SP();
                                    break;
                                case 1000000775:
                                    Play.FLD_人物_追加_防御 -= 20;
                                    Play.更新武功和状态();
                                    break;
                                case 1000000776:
                                    Play.FLD_人物_武功攻击力增加百分比 -= 0.05;
                                    Play.FLD_人物_武功防御力增加百分比 -= 0.1;
                                    Play.更新武功和状态();
                                    break;
                                default:
                                    if (FLD_PID == int.Parse(World.dt[4]))
                                    {
                                        Play.FLD_人物_复仇_经验百分比 = 0;
                                        Play.更新武功和状态();
                                    }
                                    if (FLD_PID == int.Parse(World.fc[4]))
                                    {
                                        Play.FLD_人物_复仇_经验百分比 = 0;
                                        Play.更新武功和状态();
                                    }
                                    if (FLD_PID == World.武勋保护药品)
                                    {
                                        Play.受保护状态 = false;
                                    }
                                    break;

                            }
                            if (Play.追加状态列表.ContainsKey(FLD_PID))
                            {
                                Play.追加状态列表.Remove(FLD_PID);
                            }
                            Play.状态效果(BitConverter.GetBytes(FLD_PID), 0, 0);
                            if (flag)
                            {
                                Play.更新广播人物数据();
                                Play.更新人物数据(Play);
                            }
                            Dispose();
                        }
                        else
                        {
                            Dispose();
                        }
                    }
                }
                else
                {
                    Dispose();
                }
            }
            catch (Exception)
            {
            }
            finally
            {
                Dispose();
            }
        }

        public int getsj()
        {
            return (int)time.Subtract(DateTime.Now).TotalMilliseconds;
        }
    }
}
